<template>
	<view>
		<view class="img-tx">
			<u--image src="https://cdn.uviewui.com/uview/album/1.jpg" width="80px" height="80px" shape="circle"></u--image>
		</view>

		<view class="title">
			<text>欢迎来到青梦云创平台</text>
		</view>

		<view style="padding: 20rpx;">
			<u-button open-type="getUserInfo" :customStyle="btnWX" @tap="login" text="微信授权登录"></u-button>
		</view>
		<view style="padding: 20rpx">
			<u-button :customStyle="btnPhone" @click="gotoLoginPage">手机号登录</u-button>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			btnWX: {
				backgroundColor: '#00dcb6',
				borderRadius: '20rpx',
				color: '#fff',
			},
			btnPhone:{
				backgroundColor: '#2b85e4',
				borderRadius: '20rpx',
				color: '#fff',
							
			}
		};
	},
	methods: {
		login() {
			uni.getUserProfile({
				desc: '用于完善会员资料',
				success(res) {
					console.log(res);
					if (res.userInfo) {
						wx.login({
							success(res) {
								console.log(res);
								const code = res.code;
								uni.request({
									url: 'http://localhost:8888/user/wxlogin',
									method: 'GET',
									data: {
										code: code
									},
									success(res) {
										console.log(res);
										if (res.data.code == 200) {
											console.log('登录成功');
											wx.navigateTo({
												url: '/pages/index/index'
											});
										} else {
											console.log('登录失败');
										}
									}
								});
							}
						});
					}
				}
			});
		},
		gotoLoginPage() {
			uni.navigateTo({
				url: '/subpkg/submy/sublogin/phoneLogin'
			});
		}
	}
};
</script>

<style>
.title {
	margin: 40rpx 0;
	text-align: center;
}
.img-tx{
	margin-bottom: 40rpx;
	display: flex;
	justify-content: center;
	margin-top: 200rpx;
}
</style>
